package com.threadPool.providerConsumer;

import java.util.Random;

/**
 * @author: dong peng
 * @date: 2019/6/3 18:33
 * @description:
 */

public class Consumer implements Runnable {

    private ShareResource resource;

    public Consumer(ShareResource shareResource) {
        this.resource = shareResource;
    }

    @Override
    public void run() {
        boolean flag = true;
        while (flag) {
            String s = resource.remove();
            System.out.println("消费内容： "+ Thread.currentThread().getName() + " " + s);

            if(s == null) {
                flag = false;
                System.out.println(Thread.currentThread().getName() + "   结束");
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
